<template>
  <!-- 短信配置详情抽屉 -->
  <div class="sms-pluginSmsConfig-detail">
    <el-drawer v-model="isShowDialog" size="80%" direction="ltr">
      <template #header>
        <h4>短信配置详情</h4>
      </template>
      <el-form ref="formRef" :model="formData" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="ID">{{ formData.id }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="短信平台">{{ formData.smsType }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注">{{ formData.remark }}</el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="状态">{{ proxy.getOptionValue(formData.status, statusOptions,'value','label') }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="配置"><pre>{{ formData.config }}</pre></el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-drawer>
  </div>
</template>
<script lang="ts">
  import { reactive, toRefs, defineComponent,ref,unref,getCurrentInstance,computed } from 'vue';
  import {ElMessageBox, ElMessage, FormInstance,UploadProps} from 'element-plus';
  import {
    listPluginSmsConfig,
    getPluginSmsConfig,
    delPluginSmsConfig,
    addPluginSmsConfig,
    updatePluginSmsConfig,
  } from "/@/api/plugins/sms/pluginSmsConfig";
  import {
    PluginSmsConfigTableColumns,
    PluginSmsConfigInfoData,
    PluginSmsConfigTableDataState,
    PluginSmsConfigEditState
  } from "/@/views/plugins/sms/pluginSmsConfig/list/component/model"
  export default defineComponent({
    name:"ApiV1PluginsSmsPluginSmsConfigDetail",
    components:{
    },
    props:{
      statusOptions:{
        type:Array,
        default:()=>[]
      },
    },
    setup(props,{emit}) {
      const {proxy} = <any>getCurrentInstance()
      const formRef = ref<HTMLElement | null>(null);
      const menuRef = ref();
      const state = reactive<PluginSmsConfigEditState>({
        loading:false,
        isShowDialog: false,
        formData: {
          id: undefined,
          smsType: undefined,
          remark: undefined,
          status: false ,
          config: undefined,
        },
        // 表单校验
        rules: {
          id : [
              { required: true, message: "ID不能为空", trigger: "blur" }
          ],
          smsType : [
              { required: true, message: "短信平台不能为空", trigger: "blur" }
          ],
          remark : [
              { required: true, message: "备注不能为空", trigger: "blur" }
          ],
          status : [
              { required: true, message: "状态不能为空", trigger: "blur" }
          ],
          config : [
              { required: true, message: "配置不能为空", trigger: "blur" }
          ],
        }
      });
        // 打开弹窗
        const openDialog = (row?: PluginSmsConfigInfoData) => {
          resetForm();
          if(row) {
            getPluginSmsConfig(row.id!).then((res:any)=>{
              const data = res.data;
              state.formData = data;
            })
          }
          state.isShowDialog = true;
        };
        // 关闭弹窗
        const closeDialog = () => {
          state.isShowDialog = false;
        };
        // 取消
        const onCancel = () => {
          closeDialog();
        };
        const resetForm = ()=>{
          state.formData = {
            id: undefined,
            smsType: undefined,
            remark: undefined,
            status: false ,
            config: undefined,
          }
        };
        return {
          proxy,
          openDialog,
          closeDialog,
          onCancel,
          menuRef,
          formRef,
          ...toRefs(state),
        };
      }
  })
</script>
<style scoped>
  .sms-pluginSmsConfig-detail :deep(.el-form-item--large .el-form-item__label){
    font-weight: bolder;
  }
  .pic-block{
    margin-right: 8px;
  }
  .file-block{
    width: 100%;
    border: 1px solid var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
    margin-bottom: 5px;
    padding: 3px 6px;
  }
  .ml-2{margin-right: 5px;}
</style>
